import React, { Component } from 'react'

export default class app extends Component {
    state={
        isCreated:true
    }
  render() {
    return (
      <div>
        <button onClick={()=>{
            this.setState({
                isCreated:!this.state.isCreated
            })
        }}>点击切换是否显示子组件</button>
        {this.state.isCreated ? <Child></Child> : ''}
      </div>
    )
  }
}
class Child extends  Component{
state={
timer:""
}
render(){
    return (
        <div><span>子组件内容大大玩的</span></div>
    )
}
componentDidMount(){
    window.onresize=()=>{
        console.log("resizeresizeresizeresize");
    }
    // 这种事件监听去销毁声明周期里清空
   this.timer=setInterval(()=>{
        console.log("232e32");
    },2000)
}
componentWillUnmount(){
    // 在这个生命周期里销毁定时器及window事件
    console.log("componentWillUnmountcomponentWillUnmountcomponentWillUnmount",);
    window.onresize=null
    clearInterval(this.timer)
}
}
